﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace KFGame
{
    //运行一些任务是操作
    //需要做其他任务时在这里扩展操作
    // @creator  huangchonggao@21cn.com
    //
    public class KFServerTask : MonoBehaviour
    {

        KF framework;

        public bool running = true;

        List<KFTask> tasks = new List<KFTask>();

        public void addTask(KFTask t)
        {
            tasks.Add(t);
        }


        public void clear()
        {
            tasks.Clear();
        }

        void Start()
        {
            framework = KF.kf;

            if (running)
                foreach (var item in tasks)
                {
                    item.runstart();
                }

            StartCoroutine(runTask());
        }

        IEnumerator runTask()
        {

            while (running)
            {
                yield return new WaitForSecondsRealtime(1);
                foreach (var item in tasks)
                {
                    item.runing();
                    yield return 0;
                }
            }

        }

        void OnDestroy()
        {
            if (running)
                foreach (var item in tasks)
                {
                    item.runDestroy();
                }
        }

    }
}
